FROM gradle:7.5.1-jdk17-alpine AS GRADLE_BUILD
RUN mkdir -p /usr/src/app/
COPY ./ /usr/src/app/
WORKDIR /usr/src/app/
RUN gradle build

#========================================

FROM openjdk:17-slim
ARG jarName=abstract-service-0.0.1.jar
COPY --from=GRADLE_BUILD /usr/src/app/build/libs/${jarName} /abstract-service.jar

RUN groupadd -r appuser -g 1000 && \
    useradd -u 1000 -r -g appuser -m -d /home/appuser -s /sbin/nologin -c "Docker image user" appuser
RUN chown appuser:appuser /abstract-service.jar
USER appuser

CMD ["java", "-jar", "/abstract-service.jar"]
#========================================